/**
 * Program   :   MyUserDetailsService.java
 * Author    :   shadow guo
 * Create    :   2013-6-9 上午11:14:39
 *
 * Copyright 2008 by Tongfu Information Technology Co. Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of Tongfu Information Technology Co. Ltd. ("Confidential Information").  You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with Tongfu Information Technology Co. Ltd.
 * 
 */
package com.tongfusoft.web.core.security;

import java.util.Collection;

import org.springframework.dao.DataAccessException;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import com.tongfusoft.web.core.service.ISecurityService;

public class BaseUserDetailsService implements UserDetailsService {
	private ISecurityService securityService;

	public ISecurityService getSecurityService() {
		return securityService;
	}

	public void setSecurityService(ISecurityService securityService) {
		this.securityService = securityService;
	}

	@Override
	public UserDetails loadUserByUsername(String userName)
			throws UsernameNotFoundException, DataAccessException {
		// 得到用户的权限
		Collection<GrantedAuthority> auths = this.getSecurityService()
				.loadUserAuthoritiesByName(userName);

		return new User(userName, this.getSecurityService().getPwdByName(
				userName), true, true, true, true, auths);

	}

}
